const {connection,mysqlDao} = require('../utils/jdbc-connection')
const BaseDao = require("./base-dao");
/**
 * 登录dao操作
 */
class LoginDao extends BaseDao{
    constructor() {
        super();
    }

    /**
     * 用户名密码是否存在
     * @param username
     * @param password
     */
   hasExist (username,password){
        let sql = 'select id  from user where username=? and password=?'
        return connection(sql,[username,password])
   }

    /**
     *
     * @param username
     * @param password
     */
   isExist(username,password){
       let value = ""
       let sql = 'select count(*) as count from user where username=? and password=?'
       mysqlDao(sql,[username,password],(error,values,fields)=>{
           value = values[0]
           console.log("value:",value)
       })
        console.log("value:",value)
        return value
   }

    /**
     * 获取用户信息
     * @param username
     * @param password
     * @returns {Promise<unknown>}
     */
   getUser(username,password){
       let sql = 'select * from user where username=? and password=?'
       return connection(sql,[username,password])
   }
}

module.exports = LoginDao;
